/**
 * CORS中间件配置
 */
const cors = require('cors');

const getCorsMiddleware = (enableCors) => {
  if (!enableCors) {
    return (req, res, next) => next();
  }
  
  return cors({
    origin: '*', // 允许所有来源，生产环境中应更具体
    methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
    allowedHeaders: ['Content-Type', 'Authorization']
  });
};

module.exports = getCorsMiddleware; 